<template>
  <view class="container">
    <div style="display: flex; justify-content: center">
      <div style="margin-top: 54rpx" class="btn_con" @click=handleScanRental>扫码巡检</div>
    </div>

    <!-- <div
      style="
        display: flex;
        justify-content: flex-end;
        color: #9c9c9c;
        width: 100%;
        margin-top: 16rpx;
        padding-right: 50rpx;
      "
    >
      巡检人：橘小杏
    </div> -->

    <div style="margin-top: 30rpx; padding-left: 12rpx; padding-right: 12rpx" v-if="show">
      <div style="padding: 20rpx; margin-top: 10rpx">
        <view style="padding: 30rpx; background-color: #ffffff">
          <div class="title_title">设备信息</div>

          <div class="flex">
            <div class="text" style="color: #b4b4b4">设备名称</div>
            <div>{{ info.scene_type === 1 ? "陪护床" : "轮椅" }}</div>
          </div>

          <div class="flex">
            <div class="text" style="color: #b4b4b4">设备编号</div>
            <div>{{ info.nb_device_id }}</div>
          </div>
          <!-- <div class="flex">
            <div class="text" style="color: #b4b4b4">当前状态</div>
            <div>关锁</div>
          </div> -->
          <div class="flex">
            <div class="text" style="color: #b4b4b4">是否故障</div>
            <div>否</div>
          </div>

          <div class="flex">
            <div class="text" style="color: #b4b4b4">机构</div>
            <div>{{ info.hospital.name }}</div>
          </div>

          <div class="flex">
            <div class="text" style="color: #b4b4b4">科室</div>
            <div><span>{{ info.department.build }}</span> 号楼 {{ info.department.deptname }}</div>
          </div>

          <div class="flex">
            <div class="text" style="color: #b4b4b4">楼层</div>
            <div>{{ info.department.floor }}楼</div>
          </div>
        </view>
      </div>
    </div>
  </view>
</template>

<script>
import { addInspection, getEquipmentInfo } from '../../../api';

export default {
  data() {
    return {
      // 设备号
      device_code: "",
      info: {},
      show: false
    };
  },

  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) { },

  methods: {
    // 扫码
    handleScanRental() {

      this.show = false;
      const app = this;
      uni.scanCode({
        success: async (res) => {
          uni.showToast({ title: "扫码成功" });
          console.log(res);


          let code = res.result.split("kpl/")[1];

          console.log('code', code);
          this.device_code = code;

          try {
            const _into = await addInspection({
              id: code
            })
            console.log('_into', _into);

            uni.showToast({ title: "巡检成功" });

            app.info = _into;
            app.show = true;



          } catch (error) {

          }
        },
      });
    },

  },
};
</script>

<style lang="scss" scoped>
.container {
  min-height: 100vh;
  background: #ebebeb;
}

.btn_con {
  width: 624rpx;
  height: 98rpx;
  line-height: 50rpx;
  border-radius: 42rpx;
  background: linear-gradient(92.01deg,
      rgba(87, 215, 130, 1) 38.63%,
      rgba(29, 221, 94, 1) 80.23%);
  color: rgba(255, 255, 255, 1);
  font-size: 36rpx;
  text-align: center;
  box-shadow: 0rpx 4rpx 12rpx 0rpx rgba(87, 215, 130, 1);
  font-family: PingFangSC-regular;

  display: flex;
  justify-content: center;
  align-items: center;
}

.title_title {
  color: black;
  font-size: 40rpx;
  text-align: left;
  font-family: SourceHanSansSC-regular;
  font-weight: 600;
}

.flex {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 26rpx;
}

.text {
  height: 46rpx;
  line-height: 46rpx;
  color: rgba(0, 0, 0, 1);
  font-size: 32rpx;
  text-align: left;
  font-family: SourceHanSansSC-regular;
}
</style>
